/*
 * @Author: 王庆庆
 * @Date: 2024-04-07 07:45:00
 * @LastEditors: 王庆庆
 * @LastEditTime: 2024-11-16 19:48:52
 * @Description:
 *
 */
import { createApp } from "vue";
import { createPinia } from "pinia";

import App from "./App.vue";
import router from "./router";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
// 选择语言
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
import "./styles/index.scss";
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	app.component(key, component);
}
import $ from "jquery";
window.$ = app.config.globalProperties.$ = $;
import { marked } from "marked";
import hljs from "highlight.js";
import "highlight.js/styles/atom-one-dark.css";

// 自定义渲染器
class CustomRenderer extends marked.Renderer {
	heading(obj) {
		let str = "";
		switch (obj.depth) {
			case 1:
				str = `<h1 id="heading-${obj.text}">${obj.text}</h1>`;
				break;
			case 2:
				str = `<h2 id="heading-${obj.text}">${obj.text}</h2>`;
				break;
			case 3:
				str = `<h3 id="heading-${obj.text}">${obj.text}</h3>`;
				break;
		}
		return str;
	}
	code(code, language) {
		// 使用highlight.js来高亮代码
		const validLanguage = hljs.getLanguage(language)
			? language
			: "plaintext";
		if (code) {
			return `<pre><code class="hljs ${validLanguage}">${
				hljs.highlight(code.text, { language: validLanguage }).value
			}</code></pre>`;
		}
	}
}
const renderer = new CustomRenderer();
window.renderer = renderer;
window.marked = marked;

// 不选择语言不用传第二个参数
app.use(ElementPlus, {
	locale: zhCn,
	size: "large",
});
app.use(createPinia());
app.use(router);
app.mount("#app");
